/**
 * 
 */
package com.virxue.baseweb.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.virxue.baseweb.bo.ChatRecordBo;
import com.virxue.baseweb.vo.ChatRecordVo;
import com.virxue.baseweb.vo.TradeStockParam;

/**
 * @ClassName ChatController
 * @Description TODO
 *
 * @author sunhaojie 3113751575@qq.com
 * @date 2015年11月14日 下午8:45:10
 */
@Controller
@RequestMapping("chat")
public class ChatController {

    @Autowired
    private ChatRecordBo chatRecordBo;

    @RequestMapping("show")
    public String show(HttpServletRequest request, HttpServletResponse response) {
        List<ChatRecordVo> chatRecordList = chatRecordBo.listRecently(10);
        request.setAttribute("chatRecordList", chatRecordList);
        return "chat/chat";
    }

    @RequestMapping("add")
    public String add(@ModelAttribute("username") String username, @ModelAttribute("content") String content,
                      HttpServletRequest request, HttpServletResponse response) {
        chatRecordBo.addChat(username, content);
        return show(request, response);
    }

    @ResponseBody
    @RequestMapping(value = "test", method = RequestMethod.POST)
    public Map<String, String> testRequestBody(@RequestBody TradeStockParam tradeStockParam) {

        String orderId = tradeStockParam.getOrderId();
        String productId = tradeStockParam.getProductId();
        int productType = tradeStockParam.getProductType();
        String region = tradeStockParam.getRegion();
        int num = tradeStockParam.getNum();
        String params = tradeStockParam.getParams();
        String subOrderId = tradeStockParam.getSubOrderId();
        String instanceId = tradeStockParam.getInstanceId();

        Map<String, String> result = new HashMap<String, String>();
        result.put("orderId", orderId);
        result.put("productId", productId);
        result.put("productType", productType + "");
        result.put("region", region);
        result.put("num", num + "");
        result.put("params", params);
        result.put("subOrderId", subOrderId);
        result.put("instanceId", instanceId);

        return result;
    }
}
